#include "Tools/ToolRemoveObject.h"

using namespace Ogre;
ToolRemoveObject::ToolRemoveObject(Ogre::Camera *mCam, Ogre::SceneManager *ScrMgr, Ogre::RaySceneQuery* ray)
{
	objectSelected = false;
	altPressed = false;
	mSceneMgr=ScrMgr;
	select = new ActionSelectObject(mCam,ScrMgr,ray);
	moveCam = new ActionMoveCamera(mCam);
}

ToolRemoveObject::~ToolRemoveObject(){}

void ToolRemoveObject::updateGraphics(const FrameEvent &evt){

	moveCam->updateGraphics(evt);
}

void ToolRemoveObject::mouseMoved(const OIS::MouseEvent &evt){

	moveCam->mouseMoved(evt);
}

void ToolRemoveObject::mousePressed(const OIS::MouseEvent &evt){
	
	if(!objectSelected){
		if(select->mousePressed(evt)){
			objectSelected=true;
			(select->getSelectedNode())->showBoundingBox(true);
		}
	}
	else if(select->mousePressed(evt) && select->isDeselected()){
		(select->getSelectedNode())->showBoundingBox(false);
		objectSelected=false;
	}
}

void ToolRemoveObject::keyPressed(const OIS::KeyEvent &evt){

	if(evt.key==OIS::KC_LMENU)
		altPressed=true;

	if(objectSelected)
		if(evt.key==OIS::KC_DELETE){
			mSceneMgr->destroySceneNode(select->getSelectedNode());
			objectSelected=false;
			if(!altPressed)
				MapEditor::instance()->toolEnded();
		}

	moveCam->keyPressed(evt);

}
void ToolRemoveObject::keyReleased(const OIS::KeyEvent &e){

	if(e.key==OIS::KC_LMENU)
		altPressed=false;
	moveCam->keyReleased(e);
}

void ToolRemoveObject::end(){

	MapEditor::instance()->toolEnded();
	objectSelected=false;
}